# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：     day143_pyqt5_qFileDialog
   Description :
   Author :       fuml
   date：          2019/9/22
-------------------------------------------------
   Change Activity:
                   2019/9/22:
    In this example, we determine the event sender object.
-------------------------------------------------
"""
import  sys
from PyQt5.QtWidgets import (QMainWindow,QTextEdit,QAction,QFileDialog,QApplication,QMenuBar,QMenu)
from PyQt5.QtGui import QIcon

class Example(QMainWindow):
    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):
        self.textEdit = QTextEdit()
        self.setCentralWidget(self.textEdit)
        self.statusBar()

        openfile = QAction(QIcon('Open.png'),'&Open',self)
        openfile.setShortcut('Ctrl+O')
        openfile.setStatusTip('Open new File')
        openfile.triggered.connect(self.showDialog)

        menubar:QMenuBar = self.menuBar()
        filemenu:QMenu = menubar.addMenu('&File')
        filemenu.addAction(openfile)

        self.setGeometry(300,300,250,150)
        self.setWindowTitle('File dialog')
        self.show()

    def showDialog(self):
        fname = QFileDialog.getOpenFileName(self,'Open file','F:/shared')
        printf(fname)
        '''
        if fname[0]:
            f = open(fname[0],'r')
            with f:
                data = f.read()
                printf(data)
                self.textEdit.setText(data)
'''
if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())